/*
 * Copyright (c) 2011 Metrum Research Group LLC. All Rights Reserved.
 *
 * You may use this software under the terms of GPL v3 (http://www.gnu.org/licenses/gpl.html).
 *
 * METRUM RESEARCH GROUP LLC MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. METRUM RESEARCH GROUP LLC SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package sumo;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class RTag extends BodyTagSupport {
	private boolean silent = false;
	public String getSilent() {return (new Boolean(silent).toString());}
	public void setSilent(String newSilent) {this.silent = Boolean.parseBoolean(newSilent);}
	public int doEndTag() throws JspException {
		try {
			String bodyText = bodyContent.getString();
			HttpSession theSession = pageContext.getSession();
			//OutputStream os = (OutputStream) theSession.getAttribute("SESSION_OUTPUT_STREAM");
			//os.flush();//need?
			ExpressionEvaluator R = (ExpressionEvaluator) theSession.getAttribute("evaluator");
			String result = R.evaluate(bodyText);
			if (!silent)pageContext.getOut().write(result);
		} catch (IOException e) {}
		return EVAL_PAGE;
	}
}
